package com.ruoyi.common.newAdd.returnResult;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 *
 * @author Mark sunlightcs@gmail.com
 */
public class Res extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public Res() {
        put("code", 200);
        put("msg", "success");
    }

    public static Res error() {
        return error(500, "未知异常，请联系管理员");
    }
    public static Res noUser(){
        return error(500, "用户未找到");
    }

    public static Res error(String msg) {
        return error(500, msg);
    }

    public static Res error(int code, String msg) {
        Res r = new Res();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static Res ok(int code, String msg) {
        Res r = new Res();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    //需要展示的成功信息
    public static Res okShowMsg(String msg) {
        Res r = new Res();
        r.put("code",201);
        r.put("msg", msg);
        return r;
    }

    //需要展示的失败信息
    public static Res errorShowMsg(String msg) {
        Res r = new Res();
        r.put("code",202);
        r.put("msg", msg);
        return r;
    }

    public static Res warn(String msg) {
        Res r = new Res();
        r.put("code",-1);
        r.put("msg", msg);
        return r;
    }

    public static Res ok(Map<String, Object> map) {
        Res r = new Res();
        r.putAll(map);
        return r;
    }


    public static Res ok() {
        return new Res();
    }

    @Override
    public Res put(String key, Object value) {
        super.put(key, value);
        return this;
    }
    public static Res ok(ResultCode resultCode){
        Res r = new Res();
        r.put("code", resultCode.getCode());
        r.put("msg", resultCode.getMessage());
        return r;
    }
    public static Res error(ResultCode resultCode) {
        Res r = new Res();
        r.put("code", resultCode.getCode());
        r.put("msg", resultCode.getMessage());
        return r;
    }

    public static Res exp(String msg) {
        return error(-500, msg);
    }
}
